package Service;

import models.DailyDispage;
import models.User;
import models.daily;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by 郑凯 on 2016/6/13.
 */
@Service
public class UserOpImp implements UserOpService {



    public User getUserByUid(String uid) {
        User u = Dao.UserOp.getUserByUid(uid);
        return u;
    }

    public List getListByUid(String uid) {
        List<daily> listdaily = Dao.UserOp.getDailyByUid(uid);
        return  listdaily;
    }

    public List<daily> getDailyDispage(DailyDispage dispage) {
        return Dao.UserOp.GetDailyDispage(dispage);
    }

    public daily getDailyByDid(String did){
        return Dao.UserOp.getDailyByDid(did);
    }

    public boolean saveDaily(String title, String content, String tab, String uid) {
        return Dao.UserOp.saveDaily(title,content,tab,uid);
    }

    public int getCountDailyDispageByUid(String uid) {
        int count = Dao.UserOp.getCountDailyDispageByUid(uid);
        return count % 15 == 0? count / 15 : count / 15 + 1;
    }

    public boolean deleteDailyByDid(String did) {
        return Dao.UserOp.deleteDailyByDid(did);
    }

    public void updateDailyByDid(String did, String title, String content, String tab) {
        daily d = new daily();
        d.setDid(did);
        d.setTitle(title);
        d.setContent(content);
        d.setTab(tab);
        Dao.UserOp.updateDailyByDid(d);
    }

    public void updateUserDaily(String uid) {
        Dao.UserOp.updateUserDaily(uid);
    }

    public void modifyUserInfo(String uid,String name, String password, String imagePath) {
        User user = new User();
        user.setName(name);
        user.setUid(uid);
        user.setPassword(password);
        user.setImg(imagePath);
        Dao.UserOp.updateUserByUid(user);
    }


}
